/*    */ package net.sourceforge.appgen.support;
/*    */ 
/*    */ import net.sourceforge.appgen.editor.MappingDataEditor;
/*    */ import net.sourceforge.appgen.model.Entity;
/*    */ import net.sourceforge.appgen.model.Field;
/*    */ import org.eclipse.jface.resource.ImageDescriptor;
/*    */ import org.eclipse.jface.resource.ImageRegistry;
/*    */ import org.eclipse.jface.viewers.ITableLabelProvider;
/*    */ import org.eclipse.jface.viewers.LabelProvider;
/*    */ import org.eclipse.swt.graphics.Image;
/*    */ 
/*    */ public class FieldTableLabelProvider extends LabelProvider
/*    */   implements ITableLabelProvider
/*    */ {
/* 34 */   private static ImageRegistry imageRegistry = new ImageRegistry();
/*    */   public static final String CHECKED_IMAGE = "checked";
/*    */   public static final String UNCHECKED_IMAGE = "unchecked";
/*    */ 
/*    */   static
/*    */   {
/* 40 */     String iconPath = "icon/";
/*    */ 
/* 42 */     imageRegistry.put("checked", ImageDescriptor.createFromFile(MappingDataEditor.class, iconPath + "checked" + ".gif"));
/* 43 */     imageRegistry.put("unchecked", ImageDescriptor.createFromFile(MappingDataEditor.class, iconPath + "unchecked" + ".gif"));
/*    */   }
/*    */ 
/*    */   public Image getColumnImage(Object element, int columnIndex) {
/* 47 */     if (columnIndex == 0) {
/* 48 */       Field field = (Field)element;
/*    */ 
/* 50 */       return field.isCreate() ? imageRegistry.get("checked") : imageRegistry.get("unchecked");
/*    */     }
/*    */ 
/* 53 */     return null;
/*    */   }
/*    */ 
/*    */   public String getColumnText(Object element, int columnIndex) {
/* 57 */     Field field = (Field)element;
/* 58 */     Entity entity = field.getEntity();
/*    */ 
/* 60 */     switch (columnIndex) {
/*    */     case 0:
/* 62 */       return "";
/*    */     case 1:
/* 64 */       return field.getColumnName();
/*    */     case 2:
/* 66 */       return field.getColumnType();
/*    */     case 3:
/* 68 */       return String.valueOf(field.getColumnSize());
/*    */     case 4:
/* 70 */       return field.getPkPosition() <= 0 ? "" : String.valueOf(field.getPkPosition());
/*    */     case 5:
/* 72 */       return String.valueOf(field.isNullable());
/*    */     case 6:
/* 74 */       return String.valueOf(field.isLob());
/*    */     case 7:
/* 76 */       return field.getFieldName();
/*    */     case 8:
/* 78 */       return field.getFieldType();
/*    */     case 9:
/* 81 */       if ((entity.getFieldList().size() > 0) && (entity.getFieldList().get(0) == field)) {
/* 82 */         return "";
/*    */       }
/* 84 */       return "^";
/*    */     case 10:
/* 86 */       if ((entity.getFieldList().size() > 0) && (entity.getFieldList().get(entity.getFieldList().size() - 1) == field)) {
/* 87 */         return "";
/*    */       }
/* 89 */       return "v";
/*    */     }
/* 91 */     throw new RuntimeException("column index out of range. " + columnIndex);
/*    */   }
/*    */ }
